package com.zhixiang.xaec.service.bpmndemo.impl;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhixiang.core.dao.BaseDao;
import com.zhixiang.core.service.impl.BaseServiceImpl;
import com.zhixiang.xaec.dao.bpmndemo.WorkflowConfigDao;
import com.zhixiang.xaec.entity.bpmndemo.WorkflowConfig;
import com.zhixiang.xaec.service.bpmndemo.WorkflowConfigService;


/**
 * @author gao
 * @since 2017年1月11日
 */
@Service
public class WorkflowConfigServiceImpl extends BaseServiceImpl<WorkflowConfig, Long> implements WorkflowConfigService
{

    @Override
    @Resource(type = WorkflowConfigDao.class)
    public void setBaseDao(BaseDao<WorkflowConfig, Long> dao)
    {
        setDao(dao);
    }

    @Override
    public List<WorkflowConfig> findCfgByCondition(String companyId, String variableName,
                                                   String workflowKey)
    {
        return getDao().findByHql(
            "from WorkflowConfig where companyId=? and variableName=? and workflowKey=?",
            new String[] {companyId, variableName, workflowKey});
    }

    public List<WorkflowConfig> findCfgByCondition(String companyId, String deptId, String variableName,
                                                   String workflowKey)
    {
        return getDao().findByHql(
            "from WorkflowConfig where companyId=? and departmentId=? and variableName=? and workflowKey=?",
            new String[] {companyId, deptId, variableName, workflowKey});
    }

    public List<WorkflowConfig> findCfgProcessDept(String companyId, String deptId,String workflowKey)
    {
        return getDao().findByHql(
            "from WorkflowConfig where companyId=? and departmentId=? and workflowKey=?",
            new String[] {companyId, deptId, workflowKey});
    }
    
    public List<WorkflowConfig> findCfgProcessDeptNull(String companyId, String workflowKey)
    {
        return getDao().findByHql(
            "from WorkflowConfig where companyId=? and workflowKey=? and departmentId is null",
            new String[] {companyId, workflowKey});
    }

}
